﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using DbUtility;
using MvcPager;

namespace Models
{
    #region 实体模型
    public partial class site : INotifyPropertyChanged
    {

        /// <summary>
        /// 属性更改通知
        /// </summary>
        private List<string> _ChangedList = new List<string>();
        /// <summary>
        /// 属性更改通知
        /// </summary>
        [ColumnAttribute("ChangedList", true, false, true)]
        public List<string> ChangedList { get { return _ChangedList; } }
        /// <summary>
        /// 客户端通知事件
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propName)
        {
            if (_ChangedList == null || !_ChangedList.Contains(propName))
            {
                _ChangedList.Add(propName);

            }
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));

            }
        }
        /// <summary>
        ///id
        /// </summary>
        private Int32 _id;
        /// <summary>
        ///id
        /// </summary>
        [ColumnAttribute("id", false, true, false)]
        public Int32 id { get { return _id; } set { _id = value; OnPropertyChanged("id"); } }


        /// <summary>
        ///name
        /// </summary>
        private String _name;
        /// <summary>
        ///name
        /// </summary>
        [ColumnAttribute("name", false, false, false)]
        public String name { get { return _name; } set { _name = value; OnPropertyChanged("name"); } }


        /// <summary>
        ///introduction
        /// </summary>
        private String _introduction;
        /// <summary>
        ///introduction
        /// </summary>
        [ColumnAttribute("introduction", false, false, true)]
        public String introduction { get { return _introduction; } set { _introduction = value; OnPropertyChanged("introduction"); } }


        /// <summary>
        ///logo
        /// </summary>
        private String _logo;
        /// <summary>
        ///logo
        /// </summary>
        [ColumnAttribute("logo", false, false, true)]
        public String logo { get { return _logo; } set { _logo = value; OnPropertyChanged("logo"); } }


        /// <summary>
        ///status
        /// </summary>
        private Int32? _status;
        /// <summary>
        ///status
        /// </summary>
        [ColumnAttribute("status", false, false, true)]
        public Int32? status { get { return _status; } set { _status = value; OnPropertyChanged("status"); } }


        /// <summary>
        ///isdeleted
        /// </summary>
        private Boolean _isdeleted;
        /// <summary>
        ///isdeleted
        /// </summary>
        [ColumnAttribute("isdeleted", false, false, false)]
        public Boolean isdeleted { get { return _isdeleted; } set { _isdeleted = value; OnPropertyChanged("isdeleted"); } }


        /// <summary>
        ///appid
        /// </summary>
        private String _appid;
        /// <summary>
        ///appid
        /// </summary>
        [ColumnAttribute("appid", false, false, true)]
        public String appid { get { return _appid; } set { _appid = value; OnPropertyChanged("appid"); } }


        /// <summary>
        ///appsecret
        /// </summary>
        private String _appsecret;
        /// <summary>
        ///appsecret
        /// </summary>
        [ColumnAttribute("appsecret", false, false, true)]
        public String appsecret { get { return _appsecret; } set { _appsecret = value; OnPropertyChanged("appsecret"); } }


        /// <summary>
        ///token
        /// </summary>
        private String _token;
        /// <summary>
        ///token
        /// </summary>
        [ColumnAttribute("token", false, false, true)]
        public String token { get { return _token; } set { _token = value; OnPropertyChanged("token"); } }


        /// <summary>
        ///accesstoken
        /// </summary>
        private String _accesstoken;
        /// <summary>
        ///accesstoken
        /// </summary>
        [ColumnAttribute("accesstoken", false, false, true)]
        public String accesstoken { get { return _accesstoken; } set { _accesstoken = value; OnPropertyChanged("accesstoken"); } }


        /// <summary>
        ///expiredtime
        /// </summary>
        private DateTime? _expiredtime;
        /// <summary>
        ///expiredtime
        /// </summary>
        [ColumnAttribute("expiredtime", false, false, true)]
        public DateTime? expiredtime { get { return _expiredtime; } set { _expiredtime = value; OnPropertyChanged("expiredtime"); } }


        /// <summary>
        ///ticket
        /// </summary>
        private String _ticket;
        /// <summary>
        ///ticket
        /// </summary>
        [ColumnAttribute("ticket", false, false, true)]
        public String ticket { get { return _ticket; } set { _ticket = value; OnPropertyChanged("ticket"); } }


        /// <summary>
        ///ticketexpiredtime
        /// </summary>
        private DateTime? _ticketexpiredtime;
        /// <summary>
        ///ticketexpiredtime
        /// </summary>
        [ColumnAttribute("ticketexpiredtime", false, false, true)]
        public DateTime? ticketexpiredtime { get { return _ticketexpiredtime; } set { _ticketexpiredtime = value; OnPropertyChanged("ticketexpiredtime"); } }


        /// <summary>
        ///subscribereplyid
        /// </summary>
        private Int32? _subscribereplyid;
        /// <summary>
        ///subscribereplyid
        /// </summary>
        [ColumnAttribute("subscribereplyid", false, false, true)]
        public Int32? subscribereplyid { get { return _subscribereplyid; } set { _subscribereplyid = value; OnPropertyChanged("subscribereplyid"); } }


        /// <summary>
        ///subscribecontent
        /// </summary>
        private String _subscribecontent;
        /// <summary>
        ///subscribecontent
        /// </summary>
        [ColumnAttribute("subscribecontent", false, false, true)]
        public String subscribecontent { get { return _subscribecontent; } set { _subscribecontent = value; OnPropertyChanged("subscribecontent"); } }


        /// <summary>
        ///defaultreplyid
        /// </summary>
        private Int32? _defaultreplyid;
        /// <summary>
        ///defaultreplyid
        /// </summary>
        [ColumnAttribute("defaultreplyid", false, false, true)]
        public Int32? defaultreplyid { get { return _defaultreplyid; } set { _defaultreplyid = value; OnPropertyChanged("defaultreplyid"); } }


        /// <summary>
        ///defaultcontent
        /// </summary>
        private String _defaultcontent;
        /// <summary>
        ///defaultcontent
        /// </summary>
        [ColumnAttribute("defaultcontent", false, false, true)]
        public String defaultcontent { get { return _defaultcontent; } set { _defaultcontent = value; OnPropertyChanged("defaultcontent"); } }




    }
    #endregion
    #region 基本业务
    public partial class siteLogic : BaseService
    {

        /// <summary>
        /// 构造函数
        /// </summary>
        public siteLogic()
        {
            db = new DBContext();
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="obj">操作数据库对象</param>
        public siteLogic(DBContext obj)
        {
            db = obj;
        }
        /// <summary>
        /// 添加site
        /// </summary>
        /// <param name="obj">添加对象</param>
        /// <returns>成功True失败False</returns>
        public bool Add(site obj)
        {
            try
            {
                if (obj.id > 0) throw new Exception("数据库已存在此数据");

                string result = base.Add(obj);

                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 添加site
        /// </summary>
        /// <param name="obj">添加对象</param>
        /// <returns>返回id</returns>
        public int Create(site obj)
        {
            try
            {
                if (obj.id > 0) throw new Exception("数据库已存在此数据");
                string result = base.Add(obj);
                base.Save(result);
                return Convert.ToInt32(new DBContext().ExecuteScalarSql("select max(id) from [site]"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 批量添加
        /// </summary>
        public bool Add(List<site> obj)
        {
            try
            {
                List<string> result = new List<string>();

                foreach (site item in obj)
                {
                    if (item.id == 0)
                    {
                        string sql = base.Add(item);
                        result.Add(sql);
                    }
                }

                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 修改site
        /// </summary>
        /// <param name="obj">修改对象</param>
        /// <returns>成功True失败False</returns>
        public bool Update(site obj)
        {
            try
            {
                if (obj.id == 0) throw new Exception("数据库不存在当前数据");
                string result = base.Update(obj);
                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="olts"></param>
        /// <returns></returns>
        public bool Update(List<site> olts)
        {
            try
            {
                string sql = "";
                foreach (var item in olts)
                {
                    sql += base.Update(item) + " ";
                }
                return base.Save(sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据编号删除site，此处为逻辑删除，实为更新IsDelete字段
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>成功True失败False</returns>
        public bool Delete(int id)
        {
            try
            {
                string result = base.Update(new site { id = id, isdeleted = true });

                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 删除site，此处为逻辑删除，实为更新IsDelete字段
        /// </summary>
        /// <param name="obj">删除对象</param>
        /// <returns>成功True失败False</returns>
        public bool Delete(site obj)
        {
            string sql = "";
            try
            {
                var olts = base.GetObjects<site>(obj);
                if (olts != null)
                {
                    foreach (var item in olts)
                    {
                        if (item.id > 0)
                        {
                            item.isdeleted = true;
                            sql += base.Update(item) + " ";
                        }
                    }
                    return base.Save(sql);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return false;
        }
        /// <summary>
        /// 删除site集合，此处为逻辑删除，实为更新IsDelete字段
        /// </summary>
        /// <param name="objs">删除对象集合</param>
        /// <returns>成功True失败False</returns>
        public bool Delete(IList<site> objs)
        {
            try
            {
                if (objs == null || objs.Count == 0) return false;

                StringBuilder sql = new StringBuilder();

                foreach (var item in objs)
                {
                    if (item.id > 0)
                    {
                        item.isdeleted = true;

                        string result = base.Update(item) + " ";

                        sql.Append(result);
                    }
                }

                return base.Save(sql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 根据编号删除site，物理删除
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>成功True失败False</returns>
        public bool Remove(int id)
        {
            try
            {
                string result = base.Delete(new site { id = id });

                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据编号删除site，物理删除
        /// </summary>
        /// <param name="obj">查询条件对象</param>
        /// <returns>成功True失败False</returns>
        public bool Remove(site obj)
        {
            try
            {
                if (obj.id < 1) throw new Exception("数据库不存在当前数据");
                string result = base.Delete(obj);
                return base.Save(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据编号删除site，物理删除
        /// </summary>
        /// <param name="obj">查询条件对象</param>
        /// <returns>成功True失败False</returns>
        public bool Remove(IList<site> objs)
        {
            try
            {
                string result = "";
                foreach (var obj in objs)
                {
                    if (obj.id > 0)
                    {
                        result = base.Delete(obj);
                        base.Save(result);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <returns>返回site集合</returns>
        public List<site> Getsites()
        {
            List<site> objs = base.GetObjects<site>(new site() { isdeleted = false });

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <returns>返回site集合</returns>
        public List<site> Getsites(site obj)
        {
            obj.isdeleted = false;

            List<site> objs = base.GetObjects(obj);

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <param name="where">特殊条件</param>
        /// <returns>返回site集合</returns>
        public List<site> Getsites(site obj, string where)
        {
            obj.isdeleted = false;

            List<site> objs = base.GetObjects(obj, where);

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <param name="where">特殊条件</param>
        ///  <param name="orderby">排序</param>
        /// <returns>返回site集合</returns>
        public List<site> Getsites(site obj, string where, string order)
        {
            obj.isdeleted = false;

            List<site> objs = base.GetObjects(obj, where, order, string.Empty);

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <param name="where">特殊条件</param>
        /// <param name="orderby">排序</param>
        /// <param name="orderbyType">排序类型</param>
        /// <returns>返回site集合</returns>
        public List<site> Getsites(site obj, string where, string order, string by)
        {
            obj.isdeleted = false;

            List<site> objs = base.GetObjects(obj, where, order, by);

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <returns>返回site集合</returns>
        public Page<site> Getsites(int pageIndex, int pageCount)
        {
            Page<site> objs = base.GetObjects(new site() { isdeleted = false }, pageIndex, pageCount);

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        /// <returns>返回site集合</returns>
        public Page<site> Getsites(site obj, int pageIndex, int pageCount)
        {
            obj.isdeleted = false;

            Page<site> objs = base.GetObjects(obj, pageIndex, pageCount);

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        /// <returns>返回site集合</returns>
        public Page<site> Getsites(string sql, int pageIndex, int pageCount)
        {
            Page<site> objs = base.GetObjects<site>(sql, pageIndex, pageCount);
            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        ///  <param name="where">自定义查询条件</param>
        /// <returns>返回site集合</returns>
        public Page<site> Getsites(site obj, int pageIndex, int pageCount, string where)
        {
            obj.isdeleted = false;

            Page<site> objs = base.GetObjects(obj, pageIndex, pageCount, where);

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        ///  <param name="orderby">排序</param>
        /// <returns>返回site集合</returns>
        public Page<site> Getsites(site obj, int pageIndex, int pageCount, string order, string by)
        {
            obj.isdeleted = false;

            Page<site> objs = base.GetObjects(obj, pageIndex, pageCount, string.Empty, order, by);

            return objs;
        }
        /// <summary>
        /// 获取site集合
        /// </summary>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageCount">每页多少条</param>
        /// <param name="obj">查询条件</param>
        ///  <param name="orderby">排序</param>
        /// <returns>返回site集合</returns>
        public Page<site> Getsites(site obj, int pageIndex, int pageCount, string where, string order, string by)
        {
            obj.isdeleted = false;

            Page<site> objs = base.GetObjects(obj, pageIndex, pageCount, where, order, by);

            return objs;
        }
        /// <summary>
        /// 获取site
        /// </summary>
        /// <param name="obj">查询条件</param>
        /// <returns>返回site</returns>
        public site Getsite(site obj)
        {
            obj.isdeleted = false;

            site entity = base.GetObject(obj);

            return entity;
        }
        /// <summary>
        /// 根据编号获取site
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>返回site</returns>
        public site Getsite(int id)
        {
            site entity = base.GetObject(new site { id = id, isdeleted = false });

            return entity;
        }

    }
    #endregion

    #region 基本数据库访问
    internal partial class siteService : BaseService
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public siteService()
        {
            db = new DBContext();
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="obj">操作数据库对象</param>
        public siteService(DBContext obj)
        {
            db = obj;
        }

    }
    #endregion
}